// axios前置拦截器
axios.interceptors.request.use(config=>{
    //在所有请求中加入认证token
    let token = window.sessionStorage.getItem('token')
    if(token != null){
        config.headers['Authorization'] = token
    }
    return config
},error=>{
    return Promise.reject(error)
})

//axios后置拦截器
axios.interceptors.response.use(response=>{
    //token快过期时，更换新的token
    let refToken = response.headers['x-token']
    if(refToken){
        //替换原有token
        window.sessionStorage.setItem('token',refToken);
    }
    const rs=response.data;
    //账号密码错误、权限
    if (rs.code===5002||rs.code===5006){
        alert(rs.msg)
        return;
    }
    //没登陆、超时、验签
    if (rs.code===5004||rs.code===5003||rs.code===5005){
        alert(rs.msg)
        window.location='Login.html';
        return;
    }
    return response
},error=>{
    return Promise.reject(error);
})